package com.wzy.content.api;

import com.wzy.base.exception.ValidationGroups;
import com.wzy.base.model.PageParams;
import com.wzy.base.model.PageResult;
import com.wzy.content.model.dto.*;
import com.wzy.content.model.po.CourseBase;
import com.wzy.content.service.CourseBaseInfoService;
import com.wzy.content.utils.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author wzy
 * @Date 2023/12/21 22:42
 * @description: 课程基本信息相关接口
 */
@Slf4j
@Api(value = "课程基本信息管理接口",tags = "课程基本信息管理接口")
@RestController
public class CourseBaseInfoController {

    @Autowired
    private CourseBaseInfoService courseBaseInfoService;

    @ApiOperation("课程查询接口")
    @PreAuthorize("hasAuthority('xc_sysmanager')")
    @PostMapping("/course/list")
    public PageResult<CourseBaseInfoDto> list(PageParams pageParams, @RequestBody(required=false) QueryCourseParamsDto queryCourseParams) {
        PageResult<CourseBaseInfoDto> pageResult = courseBaseInfoService.queryCourseBaseList(pageParams, queryCourseParams);
        return pageResult;
    }

    @ApiOperation("课程基础信息新增接口")
    @PostMapping("/course")
    public CourseBaseInfoDto addCourseBaseInfo(@RequestBody @Validated /*({ValidationGroups.Insert.class})*/ AddCourseDto addCourseDto){
        //机构id，由于认证系统没有上线暂时硬编码
        Long companyId = 1232141425L;
        return courseBaseInfoService.addCourserBaseInfo(companyId,addCourseDto);
    }
    @ApiOperation("根据id查询课程基本信息")
    @GetMapping("/course/{courseId}")
    public CourseBaseInfoDto getCourseBaseInfoById(@PathVariable Long courseId){
        //取出当前登录用户信息
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        System.out.println(user);
        return courseBaseInfoService.getCourseBaseInfoById(courseId);
    }

    @ApiOperation("修改课程基本信息")
    @PutMapping("/course")
    public CourseBaseInfoDto updateCourseBaseInfo(@RequestBody @Validated EditCourseDto editCourseDto){

        //机构id，由于认证系统没有上线暂时硬编码
        Long companyId = 1232141425L;
        return courseBaseInfoService.updateCourseBaseInfo(companyId,editCourseDto);
    }

    @ApiOperation("删除课程信息")
    @DeleteMapping("/course/{courseId}")
    public void deleteCourseInfo(@PathVariable Long courseId){
        //机构id，由于认证系统没有上线暂时硬编码
        Long companyId = 1232141425L;
        courseBaseInfoService.deleteCourseInfo(companyId,courseId);
    }

    @ApiOperation("查询待审核课程数量")
    @GetMapping("/course/auditCourseNum")
    public AuditCourseNumDto getAuditCourseNum(){
        Integer auditCourseNum = courseBaseInfoService.getAuditCourseNum();
        log.info("待审核课程数量为{}",auditCourseNum);
        AuditCourseNumDto auditCourseNumDto = new AuditCourseNumDto();
        auditCourseNumDto.setAuditCourseNum(auditCourseNum);
        return auditCourseNumDto;
    }
    @ApiOperation("查询待审核课程列表")
    @PostMapping("/course/authCourseList")
    public PageResult<CourseBaseInfoDto> authCourseList(PageParams pageParams, @RequestBody(required=false) QueryCourseParamsDto queryCourseParams) {
        PageResult<CourseBaseInfoDto> pageResult = courseBaseInfoService.queryAuthCourseList(pageParams, queryCourseParams);
        return pageResult;
    }
    @ApiOperation("审核课程")
    @PutMapping("/course/auditCourse")
    public void auditCourse(@RequestBody AuditCourseDto auditCourseDto){
        courseBaseInfoService.auditCourseById(auditCourseDto);
    }



}
